package com.sam;

import java.util.ArrayList;

import com.google.api.services.calendar.Calendar;
import com.google.api.services.calendar.Calendar.CalendarList.List;
import com.google.api.services.calendar.model.CalendarList;
import com.google.api.services.calendar.model.CalendarListEntry;
import com.sam.entities.CalendarsAdmisor;
import com.sam.utils.Utils;

public class BuscarCalendariosAdmisor {
	
	
	public java.util.List<CalendarsAdmisor> obtenerCalendarios(String admisor){
		java.util.List<CalendarsAdmisor> calendarsAdmisor = new ArrayList<CalendarsAdmisor>();
		try {
		
		Calendar service = Utils.getCalendarServices();
		List listaCalendario = service.calendarList().list();
		listaCalendario.getUnknownKeys().put("xoauth_requestor_id", admisor);
		listaCalendario.getUnknownKeys().put("key", "AIzaSyBJwUVfurVheN7_oJy4vBOGNKqqAIZuj-k");
		CalendarList calendarlist = listaCalendario.execute();
		
		
		
		CalendarListEntry calendarListEntry;
		int j=0;
		for (int i = 0; i < calendarlist.getItems().size(); i++) {
			calendarListEntry = calendarlist.getItems().get(i);
			 if(!calendarListEntry.getSummary().startsWith("Analista") && (!calendarListEntry.getId().contains("Contacts") && !calendarListEntry.getId().contains("contacts"))){
				 calendarsAdmisor.add(new CalendarsAdmisor(calendarListEntry.getId(), Utils.getListColors(j)));
				 j++;
				// System.out.println(calendarListEntry.getId()+"      "+calendarListEntry.getSummary());
			 }
			    
		 }
		 
		 
		 
	} catch (Exception e) {
		e.printStackTrace();
	}
	return calendarsAdmisor;
	}

}
